package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zjr
 * @version 1.0
 */
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    SupplierDao dao;
    @Override
    public Map<String,Object> supplierList(Integer page, Integer rows, String supplierName) {
        List<Supplier> suppliers = dao.supplierList(page-1, rows, supplierName);
        Map<String,Object> map = new HashMap<>();
        map.put("total",suppliers.size());
        map.put("rows",suppliers);
        return map;
    }

    @Override
    public ServiceVO saveSupplier(Integer supplierId, Supplier supplier) {
        if (supplierId == null) {
            dao.insert(supplier);
        }else {
            dao.saveSupplier(supplierId,supplier);
        }

        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    @Override
    public ServiceVO deleteSupplier(String ids) {
        dao.deleteSupplier(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
}
